﻿using BLL;
using Common;
using DevExpress.XtraEditors;
using DLL;
using gregn6Lib;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using System;
using System.Configuration;
using System.Data;
using System.IO;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class HealthEduPrints : XtraForm
    {
        private GridppReport Report = new GridppReport();
        private string Sql = string.Empty;
        /// <summary>
        /// 健康宣教打印
        /// </summary>
        /// <param name="sql">要显示在报表中的数据对应的sql语句</param>
        public HealthEduPrints(string sql)
        {
            InitializeComponent();
            this.Sql = sql;
            Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\HealthEduPrint.grf");
            Report.ConnectionString = Utility.GetDatabaseConnectionString();
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
            axGRPrintViewer1.Report = Report;
        }
        private void ReportFetchRecord()
        { 
            DataSet ds = SqlHelper.ExecuteDataset(this.Sql, CommandType.Text);
            if (ds == null) return;
            if (ds.Tables.Count <= 0) return;
            Utility.FillRecordToReport(Report, ds.Tables[0]);
        }
        private void HealthEduPrints_Load(object sender, EventArgs e)
        {
            axGRPrintViewer1.Start();
        }
    }
}